package com.deli.service.impl;

import com.alibaba.fastjson.JSON;
import com.deli.mapper.TestQuestion93Mapper;
import com.deli.service.TestQuestion93Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.LinkedHashMap;
import java.util.List;

@Service("testQuestion93Service")
@Transactional
public class TestQuestion93ServiceImpl implements TestQuestion93Service {

    @Autowired
    private TestQuestion93Mapper testQuestion93Mapper;

    @Override
    public String getAllQuestion() throws Exception {
        List<LinkedHashMap<String, Object>> allQuestion = testQuestion93Mapper.getAllQuestion();
        if (allQuestion == null || allQuestion.size() < 1) {
            throw new Exception("93题：在查询从0开始的题目时出现异常");
        }

        return JSON.toJSONString(allQuestion);
    }

    @Override
    public String selectQuestionByStartID(int startId) throws Exception {
        List<LinkedHashMap<String, Object>> questions = testQuestion93Mapper.selectQuestionByStartID(startId);
        if (questions == null || questions.size() < 1) {
            throw new Exception("93题：在查询从"+startId+"开始的题目时出现异常");
        }
        return JSON.toJSONString(questions);
    }
}
